package com.tasly.design.impl;

import com.tasly.common.IMatter;
import com.tasly.design.Builder;
import com.tasly.design.IMenu;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;

/**
 * ClassName:Menu
 * Description:
 *
 * @Author 肖宝成
 * @Create 2024/12/16 20:58
 * @Version 1.0
 */
public class PackageMenu implements IMenu {
    private List<IMatter> list = new ArrayList<>();
    private String level;
    private BigDecimal area = BigDecimal.ZERO;
    private BigDecimal totalPrice = BigDecimal.ZERO;

    private PackageMenu() {}

    public PackageMenu(String level, Double area) {
        this.level = level;
        this.area = new BigDecimal(area);
    }

    @Override
    public IMenu appendCeil(IMatter matter) {
        list.add(matter);
        totalPrice = totalPrice.add(
                area.multiply(new BigDecimal(matter.price()))
        );
        return this;
    }

    @Override
    public IMenu appendCoat(IMatter matter) {
        list.add(matter);
        totalPrice = totalPrice.add(
                area.multiply(new BigDecimal(matter.price()))
        );
        return this;
    }

    @Override
    public IMenu appendFloor(IMatter matter) {
        list.add(matter);
        totalPrice = totalPrice.add(
                area.multiply(new BigDecimal(matter.price()))
        );
        return this;
    }

    @Override
    public IMenu appendTile(IMatter matter) {
        list.add(matter);
        totalPrice = totalPrice.add(
                area.multiply(new BigDecimal(matter.price()))
        );
        return this;
    }

    @Override
    public String generatePriceSheet() {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("\n---------------------------------");
        stringBuilder.append("\n装修清单");
        stringBuilder.append("\n套餐等级：" + level);
        stringBuilder.append("\n套餐价格：" + totalPrice.setScale(2, RoundingMode.HALF_UP) + "元");
        stringBuilder.append("\n房屋面积:" + area.setScale(2, RoundingMode.HALF_UP) + "平米");
        stringBuilder.append("\n材料清单：");
        for (IMatter item : list) {
            stringBuilder.append("\n"
                    + item.scene() + "："
                    + item.brand() + "、"
                    + item.model() + "、平米价格："
                    + item.price() + "元");
        };
        return stringBuilder.toString();
    }
}
